<template>
  <view class="container" style="padding-bottom: 100px" v-if="isLoaded">
    <!-- 表单 -->
    <view class="content">
      <li-form>
        <li-form-item label="分组名称" required>
          <li-input
            v-model="form.name"
            rule="trim"
            prop="name"
            @blur="onBlurEvent($event)"
          />
        </li-form-item>
      </li-form>
    </view>

    <li-bottom-btns
      :mode="mode"
      @btnDelClick="btnDelClick"
      @btnEditOrSaveSubmitClick="btnEditOrSaveSubmitClick"
    />
  </view>
</template>
<script>
import liFormMixin from "../../../mixins/liFormMixin";
import {
  GetFoodTaskCategoryById,
  DelFoodTaskCategory,
  AddFoodTaskCategory,
  EditFoodTaskCategory,
} from "../../../common/api.js";

import { transferTypeEnum } from "../../../common/dataTransfer.js";
import {
  checkerType,
  modeEnum,
  booleanEnum,
} from "../../../constants/normalConstants.js";
import { corpId, storeId } from "../../../constants/apiConstants.js";
export default {
  mixins: [liFormMixin],
  async onLoad(options) {
    this.loadEvent(options, this);
  },

  async mounted() {
    this.mountedEvent(this, {
      corpId,
      storeId,
      name: "",
    });
  },
  data() {
    return {
      modeEnum,
      booleanEnum,
      subject: "做法分组", // 主题
      rootRoute: "workbench",
      routeName: "taskcategory",
      mode: "add", // 模式
      isLoaded: false,
      id: null,
      /* 表单 */
      form: null,
      /* 弹窗 */

      // 数据转换器
      transferRules: [
        /*   {
              name: "depositMoney",
              type: transferTypeEnum.float,
            },
         */
      ],
      //表单校验规则
      rules: [
        {
          name: "name",
          checkType: checkerType.endNotNull,
          errorMsg: "做法分组名字不能为空",
        },
      ],
      lock: false, // 节流锁

      /* 额外数据 */
      /* 额外校验规则 */

      /* 额外转换器 */
    };
  },

  methods: {
   
    onBlurEvent(e) {
      this.formBlur(e, this);
    },
    
    async getData() {
      this.form = (await GetFoodTaskCategoryById(this.id)).data;
    },
    
    async getOtherData() {
      // ..
    },
   
    async insertData() {
      return AddFoodTaskCategory(this.form);
    },
    
    async delData() {
      return await DelFoodTaskCategory(this.id);
    },
    
    async editData() {
      return await EditFoodTaskCategory(this.form);
    },

    
    async btnDelClick() {
      await this.formDelete(this);
    },
    
    async btnEditOrSaveSubmitClick() {
      await this.formInsertOrEdit(this);
    },

    /* 额外方法放下面，上面是主干方法 */

    //方法放上面
  },
};
</script>
<style lang="scss" scoped>
@import "~@/static/styles/commonStyle.scss";
</style>
